package com.atom.wyz.new_opengl.util;

import java.util.Set;

public class Normal {
    public static final float DIFF = 0.0000001f;
    float nx;float ny;float nz;

    public Normal(float nx, float ny, float nz) {
        this.nx = nx;
        this.ny = ny;
        this.nz = nz;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Normal) {
            Normal tn = (Normal) obj;
            if (Math.abs(nx - tn.nx) < DIFF && Math.abs(ny - tn.ny) < DIFF
                    && Math.abs(ny - tn.ny) < DIFF) {
                return true;
            } else {return false;}
        } else {return false;}
    }

    @Override
    public int hashCode() {
        return 1;
    }

    public static float[] getAverage(Set<Normal> sn){
        float[] result = new float[3];
        for (Normal n : sn) {
            result[0] += n.nx;result[1] += n.ny;result[2] += n.nz;
        }
        return LoadUtil.vectorNormal(result);//将􏳝和后的法向量􏳡􏳢化以得到平均法向量
    }
}
